﻿<UserControl x:Class="FR.SAFTAnalyser.Views.GeneralLedgerEntriesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <DockPanel Grid.Row="0" Grid.Column="0">

            <DockPanel DockPanel.Dock="Top">
                <Label Content="Diários" DockPanel.Dock="Left" Margin="3"/>
                <toolkit:WatermarkTextBox 
                    DockPanel.Dock="Top" Margin="3" TabIndex="2"
                    Text="{Binding FilterGeneralLedgerEntriesJournal, UpdateSourceTrigger=PropertyChanged}"
                    Watermark="Filtro por: Código ou Descrição"/>
            </DockPanel>

            <DataGrid x:Name="dataGridGeneralLedgerEntriesJournal" DockPanel.Dock="Bottom" TabIndex="1"
                      ItemsSource="{Binding GeneralLedgerEntriesJournal, IsAsync=True}" 
                      SelectedItem="{Binding Journal}" >
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Código" Binding="{Binding JournalID}" Width="Auto"/>
                    <DataGridTextColumn Header="Descrição" Binding="{Binding Description}" Width="Auto"/>
                </DataGrid.Columns>
            </DataGrid>
        </DockPanel>

        <DockPanel Grid.Row="0" Grid.Column="1">

            <DockPanel DockPanel.Dock="Top">
                <Label Content="Movimentos" DockPanel.Dock="Left" Margin="3"/>
                <toolkit:WatermarkTextBox 
                    DockPanel.Dock="Top" Margin="3" TabIndex="2"
                    Text="{Binding FilterTransactions, UpdateSourceTrigger=PropertyChanged}"
                    Watermark="Filtro por: Nº transação ou Periodo ou Código utilizador ou Descrição ou Nº arquivo ou Tipo"/>
            </DockPanel>
            
            
            <DataGrid x:Name="dataGridTransactions" DockPanel.Dock="Bottom" 
                              ItemsSource="{Binding Transactions, IsAsync=True}"
                              SelectedItem="{Binding Transaction}">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Nº transação" Binding="{Binding TransactionID}" />
                    <DataGridTextColumn Header="Periodo" Binding="{Binding Period}"/>
                    <DataGridTextColumn Header="Data" Binding="{Binding TransactionDate}"/>
                    <DataGridTextColumn Header="Código utilizador" Binding="{Binding SourceID}" />
                    <DataGridTextColumn Header="Descrição" Binding="{Binding Description}" />
                    <DataGridTextColumn Header="Nº arquivo" Binding="{Binding DocArchivalNumber}" />
                    <DataGridTextColumn Header="Tipo" Binding="{Binding TransactionType}" />
                    <DataGridTextColumn Header="Data gravação" Binding="{Binding GLPostingDate}" />
                </DataGrid.Columns>
            </DataGrid>
        </DockPanel>
        <GridSplitter Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0" VerticalAlignment="Center" Margin="5"
                      ShowsPreview="True" Height="5" ResizeDirection="Rows" />

        <DockPanel Grid.Row="2" Grid.Column="1">

            <DockPanel DockPanel.Dock="Top">
                <Label Content="Linhas" DockPanel.Dock="Left" Margin="3"/>
                <toolkit:WatermarkTextBox 
                    DockPanel.Dock="Top" Margin="3" TabIndex="2"
                    Text="{Binding FilterTransactionLines, UpdateSourceTrigger=PropertyChanged}"
                    Watermark="Filtro por: Nº registo ou Nº conta ou Descrição ou ID movimento contabilístico"/>
            </DockPanel>
            
            <DataGrid x:Name="dataGridTransactionLines" DockPanel.Dock="Bottom"
                      ItemsSource="{Binding TransactionLines, IsAsync=True}">
            <DataGrid.Columns>
                    <DataGridTextColumn Header="Nº registo" Binding="{Binding RecordID}"/>
                    <DataGridTextColumn Header="Nº conta" Binding="{Binding AccountID}" />
                    <DataGridTextColumn Header="Data" Binding="{Binding SystemEntryDate}" />
                    <DataGridTextColumn Header="Descrição" Binding="{Binding Description}" />
                    <DataGridTextColumn Header="ID movimento contabilístico" Binding="{Binding SourceDocumentID}" />
                    <DataGridTextColumn Header="Valor" Binding="{Binding Item}" />
                    <DataGridTextColumn Header="Tipo" Binding="{Binding ItemElementName}" />
            </DataGrid.Columns>
        </DataGrid>

        </DockPanel>

        <DockPanel Grid.Row="2" Grid.Column="0">
            <GroupBox Header="Totais" Margin="5" Padding="3" DockPanel.Dock="Top">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <TextBlock Text="Totais SAFT:" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" FontSize="14" FontWeight="SemiBold" Margin="3"/>

                    <TextBlock Text="Documentos:" Grid.Column="0" Grid.Row="1" Margin="3"/>
                    <TextBlock Text="Total crédito:" Grid.Column="0" Grid.Row="2" Margin="3"/>
                    <TextBlock Text="Total débito:" Grid.Column="0" Grid.Row="3" Margin="3"/>

                    <TextBlock Text="{Binding NumberOfEntries}" Grid.Column="1" Grid.Row="1" Margin="3" />
                    <TextBlock Text="{Binding TotalCredit}" Grid.Column="1" Grid.Row="2" Margin="3"/>
                    <TextBlock Text="{Binding TotalDebit}" Grid.Column="1" Grid.Row="3" Margin="3"/>

                    <TextBlock Text="Soma valores:" Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="2" FontSize="14" FontWeight="SemiBold" Margin="3" />

                    <TextBlock Text="Documentos:" Grid.Column="2" Grid.Row="1" Margin="3"/>
                    <TextBlock Text="Total crédito:" Grid.Column="2" Grid.Row="2" Margin="3"/>
                    <TextBlock Text="Total débito:" Grid.Column="2" Grid.Row="3" Margin="3"/>

                    <TextBlock Text="{Binding DocNumberOfEntries}" Grid.Column="3" Grid.Row="1" Margin="3" />
                    <TextBlock Text="{Binding DocTotalCredit}" Grid.Column="3" Grid.Row="2" Margin="3"/>
                    <TextBlock Text="{Binding DocTotalDebit}" Grid.Column="3" Grid.Row="3" Margin="3"/>
                </Grid>
            </GroupBox>

            <StackPanel Orientation="Horizontal">
                <Button Width="150" Height="25" Margin="5" Padding="3" ToolTip="Exportar para Excel"
                        Command="{Binding DoPrintCommand}"
                        CommandParameter="{Binding ElementName=dataGridGeneralLedgerEntriesJournal}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{StaticResource Excel}"/>
                        <TextBlock Text="Diários" Padding="5,0,0,0"/>
                    </StackPanel>
                </Button>

                <Button Width="150" Height="25" Margin="5" Padding="3" ToolTip="Exportar para Excel"
                        Command="{Binding DoPrintCommand}"
                        CommandParameter="{Binding ElementName=dataGridTransactions}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{StaticResource Excel}"/>
                        <TextBlock Text="Movimentos" Padding="5,0,0,0"/>
                    </StackPanel>
                </Button>

                <Button Width="150" Height="25" Margin="5" Padding="3" ToolTip="Exportar para Excel"
                        Command="{Binding DoPrintCommand}"
                        CommandParameter="{Binding ElementName=dataGridTransactionLines}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{StaticResource Excel}"/>
                        <TextBlock Text="Linhas" Padding="5,0,0,0"/>
                    </StackPanel>
                </Button>
            </StackPanel>
        </DockPanel>
    </Grid>
</UserControl>
